home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 157_01 / qed11 < prev    next >
Text File  |  1987-10-10  |  8KB  |  388 lines

  1. /*  VERSION 0007  (DATE: 04/04/87)  (TIME: 17:58)  */
  2. /*
  3.     e (qe) screen editor
  4.  
  5.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  6.  
  7.     August-December 1981
  8.  
  9.     Modified: Aug-Dec     1984:  BDS-C 'e' to 'qe'             (J.W.Haefner)
  10.               March        1985:  BDS-C 'qe' to DeSmet-C 'qed' (J.W.Haefner)
  11.  
  12.     FILE: qed11
  13.  
  14.     FUNCTIONS: putvrsn,comntsym,inc_v_num,usstr,has_vrsn,
  15.                makvrsn,now,vrsntail,putdate,puttime,formatnow,
  16.                index
  17.  
  18.     PURPOSE: put version num and date/time on top of file
  19.  
  20. */
  21.  
  22. #include "qed.h"
  23.  
  24. #if VRSNNUM
  25. /* putvrsn -- find and replace version number at top of file */
  26. putvrsn()
  27. {
  28.     int vline,oldcline;
  29.     char *vpos,*numpos,vtext[80];
  30.  
  31.     if (version) {  /*global flag set in ^QK*/
  32.         altered=YES;        /*force save*/
  33.         puttext();
  34.         oldcline=cline;
  35.         if (has_vrsn(&vline,&vpos) == FAIL) {
  36.             if(makvrsn(vtext)==FAIL)  {
  37.                 gettext(oldcline);     /*25.III.87*/
  38.                 return FAIL;    /*28.I.87*/
  39.             }
  40.             else oldcline++;
  41.         }
  42.         else  {
  43.              numpos=comntsym(text,vpos);
  44.             inc_v_num(text,numpos);
  45. #if VRSNDATE
  46.             if(now()==FAIL) return FAIL;    /*28.I.87*/
  47. #else
  48.             strcpy(date,"00/00/00");
  49.             strcpy(time,"00:00");
  50. #endif
  51.             vrsntail(text);
  52.             altered=YES;
  53.             puttext();
  54.         }
  55.         gettext(oldcline);        /* recover old cline text */
  56.     }
  57. }
  58.  
  59. /*comntsym -- get comment symbols, truncate version line after number*/
  60. /*              return address of beginning of version number */
  61. char *comntsym(v,vpos)
  62. char *v,*vpos;
  63. {
  64.     char *tp,*numpos;
  65.     int len;
  66.  
  67.     comnt[0]=v[0];
  68.     comnt[1]=v[1];
  69.     comnt[3]=v[(len=(strlen(v)-1))];
  70.     comnt[2]=v[(--len)];
  71.     comnt[4]='\0';
  72.     for (tp=vpos;(*tp) && (*tp!=' ');tp++);     /*tp==>1st blnk after "version"*/
  73.     while ((*tp) && ((*tp++) == ' ') );
  74.         /*found nonblank after "VERSION"*/
  75.     numpos=tp-1;
  76.     while((*tp) && ((*tp++) != ' ') );  /*break at next blank*/
  77.     *(--tp)='\0';        /*truncate old version line after numerals*/
  78.     return (numpos);
  79. }
  80.     
  81. /* inc_v_num -- increment the version number */
  82. inc_v_num(v,npos)
  83. char *v,*npos;
  84. {
  85.     char numstr[6];
  86.     int version;
  87.  
  88.     /*movmem(npos,numstr,4);*/
  89.     _move(4,npos,numstr);
  90.     numstr[4]='\0';
  91.     version=qatoi(numstr);
  92.     version++;
  93.     usstr(version,numstr,4);
  94.     numstr[4]='\0';
  95.     /*movmem(numstr,npos,4);*/
  96.     _move(4,numstr,npos);
  97. }
  98.  
  99. /* usstr -- unsigned int to string conversion */
  100. usstr(val,buf,len)
  101. int val;
  102. char *buf;
  103. int len;
  104. {
  105.     int temp,i,bufsz;
  106.  
  107.     /*bufsz=sizeof buf;*/
  108.     bufsz=len;
  109.       /*use memfill()*/
  110.     for (i=0;i<bufsz; buf[i++]='0');        /*fill with leading zeroes*/
  111.     i=bufsz-1;
  112.     while (val>0 && i>=0) {
  113.         buf[i--] = (val%10)+0x30;
  114.         val=val/10;
  115.     }
  116. /*
  117.     do {
  118.         buf[i--] = (val%10)+0x30;
  119.         val=val/10;
  120.     } while (i>=0);
  121. */
  122.     buf[bufsz]='\0';
  123. }
  124.  
  125. /* has_vrsn -- check for existing version number comment */
  126. /*             return FAIL if none, line number and address if found */
  127. int has_vrsn(vline,vpos)
  128. int *vline;
  129. char **vpos;
  130. {
  131.     int pos,line;
  132.  
  133.     line=1;
  134.     pos=-1;
  135.     do {
  136.         gettext(line);
  137.         if (text[0] != '\0')
  138.             pos=index(text,"VERSION");  /*not the DeSmet func*/
  139.         line++;
  140.     } while (text[0]=='\0' && line<=lastl);
  141.     *vline=line-1;
  142.     if (pos!=FAIL) {
  143.         *vpos=&(text[pos]);
  144.         /*error("VERSION found");*/
  145.         return YES;
  146.     }
  147.     return FAIL;
  148. }
  149.  
  150. /* makvrsn -- create a version line where none was */
  151. makvrsn(v)
  152. char *v;
  153. {
  154.     char ans[6];
  155.     
  156.     ans[0]='\0';
  157.     if (expert) xprtmess("Left sym (2): ");
  158.     else putmess("Enter left comment symbol (2 digits): ");
  159.     scans(ans,4);
  160.     if(ans[0]=='~') return FAIL;    /*bail out: no version*/
  161.     if (!(*ans)) {
  162.          comnt[0]='/';  /*guess this guy is using C*/
  163.         comnt[1]='*';
  164.     }
  165.     else {
  166.         comnt[0]=ans[0];
  167.         comnt[1]=ans[1];
  168.     }
  169.     ans[0]='\0';
  170.     if (expert) xprtmess("Right sym (2): ");
  171.     else putmess("Enter right comment symbol (2 digits): ");
  172.     scans(ans,4);
  173.     if (!(*ans)) {
  174.         comnt[2]='*';
  175.         comnt[3]='/';
  176.     }
  177.     else {
  178.         comnt[2]=ans[0];
  179.         comnt[3]=ans[1];
  180.     }
  181.     comnt[4]='\0';
  182. #if VRSNDATE
  183.     now();
  184. #else
  185.     strcpy(date,"00/00/00");
  186.     strcpy(time,"00:00");
  187. #endif
  188.     v[0]=comnt[0];
  189.     v[1]=comnt[1];
  190.     v[2]='\0';
  191.     strcat(v,"  VERSION 0000");
  192.     vrsntail(v);
  193.       /* put v as first line in editing text */
  194.     inject(0,v);
  195. }
  196.  
  197. /* vrsntail -- put tail on version line */
  198. vrsntail(v)
  199. char *v;
  200. {
  201.     int i;
  202.  
  203.     strcat(v,"  (DATE: ");
  204.     strcat(v,date);
  205.     strcat(v,")  (TIME: ");
  206.     strcat(v,time);
  207.     strcat(v,")");
  208.     for (i=(strlen(v));i<(VRSNLEN-5);i++) v[i]=' ';
  209.     v[(i++)]=comnt[2];
  210.     v[(i++)]=comnt[3];
  211.     v[(i)]='\0';
  212. }
  213. #endif  /*VRSNNUM*/
  214.  
  215.  
  216. #if VRSNDATE
  217.  
  218. /* now -- get time and date from system or user */
  219. now()
  220. {
  221. #if NOCLOCK
  222.     char temp[10];
  223. #else
  224.     int yr,mon,day;
  225.     int hr,min;
  226.     char nstr[3];        /*hold number string*/
  227. #endif
  228.  
  229. #if NOCLOCK        /* no clock, get date and time from user */
  230.     if (date[0]=='\0') formatnow(date,time);   /*get from CP/M page 0 and format*/
  231.     if (expert) xprtmess("Date(da/mn/yr): ");
  232.     else
  233.         putmess("Enter today's date as da/mn/yr (2 digit): ");
  234.     strcpy(temp,date);
  235.     /*puts(temp);*/
  236.     if (*date) {
  237.         inbuf[0]=RETRIEVE;            /*play back current date*/
  238.         if (!inbufp)inbufp=1;
  239.     }
  240.     scans(temp,10);
  241.       /*parse and convert to int*/
  242.     if (temp[8]=='~')return FAIL;    /*bail out w/o versionizing*/
  243.     if (strcmp(temp,date)!=0) {        /*date has been changed*/
  244.         strcpy(date,temp);
  245.         putdate();
  246.     }
  247.     if (expert) xprtmess("Time(24hr:mn): ");
  248.     else
  249.         putmess("Enter current time as hr:mn (24 hour): ");
  250.     strcpy(temp,time);
  251.     /*puts(temp);*/
  252.     if (*time) {
  253.         inbuf[0]=RETRIEVE;
  254.         if (!inbufp)inbufp=1;
  255.     }
  256.     scans(temp,7);
  257.         /*parse and convert to int*/
  258.     if (strcmp(temp,time)!=0) {        /*time has been changed*/
  259.         strcpy(time,temp);
  260.         puttime();
  261.     }
  262. #else            /* access system clock */
  263.     /*put code to read and decode system clock here*/
  264.       /*get date func = 2a*/
  265.     _rax=(0x2a << 8);
  266.     _rdx=0;
  267.     _doint(DOSINT);
  268.     yr=_rcx;
  269.     mon=(_rdx >> 8);
  270.     day=(_rdx & 0x00ff);
  271.       /*get time func = 2c*/
  272.     _rax=(0x2c << 8);
  273.     _rdx=0;
  274.     _rcx=0;
  275.     _doint(DOSINT);
  276.     hr=(_rcx >> 8);
  277.     min=(_rcx & 0x00ff);
  278.       /*convert and store in globals "date" and "time" */
  279.         /*unsigned short int (char) to string conversion*/
  280.         /*return next address*/
  281.     usstr(day,nstr,2);        /*date first*/
  282.     strcpy(date,nstr);
  283.     strcat(date,"/");
  284.     usstr(mon,nstr,2);
  285.     strcat(date,nstr);
  286.     strcat(date,"/");
  287.     usstr(yr,nstr,2);
  288.     strcat(date,nstr);
  289.         /*now do time*/
  290.     usstr(hr,nstr,2);
  291.     strcpy(time,nstr);
  292.     strcat(time,":");
  293.     usstr(min,nstr,2);
  294.     strcat(time,nstr);
  295. #endif
  296. }
  297.  
  298. #if NOCLOCK
  299. /* putdate -- parse date string and store as chars in CP/M page 0*/
  300. putdate()
  301. {
  302.     char temp[4],*nptr;
  303.  
  304.     nptr=NOWLOC;
  305.     temp[0]=date[0];    /*day*/
  306.     temp[1]=date[1];
  307.     temp[2]='\0';
  308.     *nptr++=qatoi(temp);
  309.     temp[0]=date[3];    /*month*/
  310.     temp[1]=date[4];
  311.     temp[2]='\0';
  312.     *nptr++=qatoi(temp);
  313.     temp[0]=date[6];    /*year*/
  314.     temp[1]=date[7];
  315.     temp[2]='\0';
  316.     *nptr=qatoi(temp);
  317. }
  318.  
  319. /* puttime -- parse time string and store as chars in CP/M page 0*/
  320. puttime()
  321. {
  322.     char temp[5],*nptr;
  323.  
  324.     nptr=NOWLOC+3;
  325.     temp[0]=time[0];    /*hour*/
  326.     temp[1]=time[1];
  327.     temp[2]='\0';
  328.     *nptr++=qatoi(temp);
  329.     temp[0]=time[3];    /*minute*/
  330.     temp[1]=time[4];
  331.     temp[2]='\0';
  332.     *nptr=qatoi(temp);
  333. }
  334.  
  335. /* formatnow -- get date and time integers from CP/M page 0, format */
  336. formatnow(d,t)
  337. char *d,*t;
  338. {
  339.       /* read 5 bytes from NOWLOC corresponding to day, month, year,
  340.            hour, minute */
  341.     char *nptr;
  342.     char nstr[3];    /*hold number string */
  343.     char day,month,year,hour,minute;
  344.  
  345.     nptr=NOWLOC;
  346.     day=*nptr++;
  347.     month=*nptr++;
  348.     year=*nptr++;
  349.     hour=*nptr++;
  350.     minute=*nptr;
  351.         /*unsigned short int (char) to string conversion*/
  352.         /*return next address*/
  353.     usstr(day,nstr,2);        /*date first*/
  354.     strcat(d,nstr);
  355.     strcat(d,"/");
  356.     usstr(month,nstr,2);
  357.     strcat(d,nstr);
  358.     strcat(d,"/");
  359.     usstr(year,nstr,2);
  360.     strcat(d,nstr);
  361.         /*now do time*/
  362.     usstr(hour,nstr,2);
  363.     strcat(t,nstr);
  364.     strcat(t,":");
  365.     usstr(minute,nstr,2);
  366.     strcat(t,nstr);
  367. }
  368. #endif  /*noclock*/
  369.  
  370. /* index -- find pattern in target */
  371. /*            return index in array at beginning patt in targ*/
  372. /*            Note: replaces DeSmet's version */
  373. index(targ,patt)
  374. char *targ,*patt;
  375. {
  376.     char pc;
  377.     char *tp1,*tp2,*pp;
  378.  
  379.     if (*targ=='\0' || *patt=='\0') return -1;
  380.     for (tp1=targ;*tp1;tp1++) {
  381.         for(tp2=tp1,pp=patt;( (pc=(*pp++)) && (pc==(*tp2++)) ););
  382.          if (pc